package com.zl.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zl.dao.RoleDao;
import com.zl.entity.Role;

@Service
public class RoleService {
	@Autowired
	private RoleDao roleDao;
	
	/**
	 * 判断最小用户等级
	 * @param role
	 * @return
	 */
	public boolean isMinGrade(Role role){
		Role roleM = roleDao.selectMinGrade();
		if(role.getId().equals(roleM.getId())){
			return true;
		}else{
			return false;
		}
		
	}
	public Role getMinRole(){
		Role roleM = roleDao.selectMinGrade();
		return roleM;
	}
	/**
	 * 判断最大用户等级
	 * @param role
	 * @return
	 */
	public boolean isMaxGrade(Role role){
		Role roleM = roleDao.selectMaxGrade();
		if(role.getId().equals(roleM.getId())){
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 判断是不是集团用户
	 * @param role
	 * @return
	 */
	public boolean isGroup(Role role){
		boolean isGroup = false;
		List<Role> groupList = roleDao.getGroup();
		for(Role roleM:groupList){
			if(role.getId().equals(roleM.getId())){
				isGroup = true;
			}
		}
		return isGroup;
	}
	
	/**
	 * 得到升级的费用
	 * @param role
	 * @return
	 */
	public int getAddPay(Role role){
		Role updateRole = roleDao.getUpdateRole(role);
		return Integer.parseInt(updateRole.getPayMonth())-Integer.parseInt(role.getPayMonth());
	}
	
	public Role getRoleByGrade(String grade){
		Role role = roleDao.getRoleByGrade(grade);
		return role;
	}
	
	public Role getUpdateRole(Role role){
		Role updateRole = roleDao.getUpdateRole(role);
		return updateRole;
	}
	
	
	public Role getRoleById(String roleId){
		Role role = roleDao.getRoleById(roleId);
		return role;
	}
}
